package dyyx.dto;

import java.io.IOException;
import java.sql.Connection;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import dyyx.util.JdbcUtil;

public class MysqlClient{

	public final Connection connection;

	// public final String name;
	public final String driver = "com.mysql.jdbc.Driver";

	public final String url;
	public final String userName ;
	public final String userPwd ;


	public final String createTime ;

	
	public MysqlClient(String url,String userName,String userPwd)throws IOException{

		if(StringUtils.isBlank(url)) {
			throw new RuntimeException("url is blank");
		}
		
		this.url = url;
		this.userName = userName;
		this.userPwd = userPwd;

        
		
		this.connection = JdbcUtil.getConnection(driver, url, userName, userPwd);
		this.createTime = LocalDateTime.now().toString();
		
	}
	
	@Override
	public String toString() {
		Map<String,String> map = new LinkedHashMap<>();
		map.put("url", url);
		map.put("user", userName);
		map.put("createTime", createTime);


		return map.toString();
	}

}
